# Simple API Test Script
Write-Host "Testing Student Management API..." -ForegroundColor Cyan

# Test 1: Health Check
Write-Host "`n[1] Health Check..." -ForegroundColor Yellow
try {
    $health = Invoke-RestMethod -Uri "http://localhost:3001/health" -Method GET
    Write-Host "OK - Server is running" -ForegroundColor Green
} catch {
    Write-Host "ERROR - Server not running" -ForegroundColor Red
    exit
}

# Test 2: Create Student
Write-Host "`n[2] Create Student..." -ForegroundColor Yellow
$student = @{
    studentNo = "20250001"
    name = "Test Student"
    className = "Class 1"
    grade = 90
}
$json = $student | ConvertTo-Json
try {
    $result = Invoke-RestMethod -Uri "http://localhost:3001/api/students" -Method POST -Body $json -ContentType "application/json"
    Write-Host "OK - Student created: $($result.data.name)" -ForegroundColor Green
    $studentId = $result.data.id
} catch {
    Write-Host "INFO - Student may already exist" -ForegroundColor Yellow
}

# Test 3: Get Students List
Write-Host "`n[3] Get Students List..." -ForegroundColor Yellow
try {
    $result = Invoke-RestMethod -Uri "http://localhost:3001/api/students" -Method GET
    Write-Host "OK - Found $($result.data.pagination.total) students" -ForegroundColor Green
} catch {
    Write-Host "ERROR - Failed to get students" -ForegroundColor Red
}

# Test 4: Get Statistics
Write-Host "`n[4] Get Statistics..." -ForegroundColor Yellow
try {
    $result = Invoke-RestMethod -Uri "http://localhost:3001/api/students/analysis/statistics" -Method GET
    Write-Host "OK - Total: $($result.data.basic.totalStudents), Avg: $($result.data.basic.avgGrade)" -ForegroundColor Green
} catch {
    Write-Host "ERROR - Failed to get statistics" -ForegroundColor Red
}

Write-Host "`nAll tests completed!" -ForegroundColor Cyan
